package com.superc.model.audio;

import java.io.Serializable;

import android.media.AudioFormat;
import android.media.AudioRecord;

import com.superc.lib.helper.KeyValue;

public class RecordSetting implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int sampleRate = 8000;
	private int channel = AudioFormat.CHANNEL_CONFIGURATION_MONO;
	private int encoding = AudioFormat.ENCODING_PCM_16BIT;
	private int bufferSize = 0;
	
	public static final String RecordSettingKey="RecordSetting";
    
	
	
	public RecordSetting(int sampleRate, int channel, int encoding, int bufferSize) {
	    this.sampleRate = sampleRate;
		this.channel = channel;
		this.encoding = encoding;
		this.bufferSize = bufferSize;
	}

	public RecordSetting(){
		this.bufferSize= AudioRecord.getMinBufferSize(sampleRate, channel, encoding);
	}
	
	public int getSampleRate() {
		return sampleRate;
	}

	public void setSampleRate(int sampleRate) {
		this.sampleRate = sampleRate;
	}

	public int getChannel() {
		return channel;
	}

	public void setChannel(int channel) {
		this.channel = channel;
	}

	public int getEncoding() {
		return encoding;
	}

	public void setEncoding(int encoding) {
		this.encoding = encoding;
	}

	public int getBufferSize() {
		return bufferSize;
	}

	public void setBufferSize(int bufferSize) {
		this.bufferSize = bufferSize;
	}
	
	@SuppressWarnings("unchecked")
	public static KeyValue<String,Integer>[] getAllChannel(){
		return new KeyValue[]{new KeyValue<String,Integer>("STEREO",AudioFormat.CHANNEL_CONFIGURATION_STEREO), 
				new KeyValue<String,Integer>("MONO",AudioFormat.CHANNEL_CONFIGURATION_MONO),
				new KeyValue<String,Integer>("DEFAULT",AudioFormat.CHANNEL_CONFIGURATION_DEFAULT)}; 
	}
	
	@SuppressWarnings("unchecked")
	public static KeyValue<String,Integer>[] getAllEncoding(){
		return new KeyValue[]{new KeyValue<String,Integer>("16bit",AudioFormat.ENCODING_PCM_16BIT), 
				new KeyValue<String,Integer>("8Bit",AudioFormat.ENCODING_PCM_8BIT),new KeyValue<String,Integer>("DEFAULT",AudioFormat.ENCODING_DEFAULT)}; 
	}
	
	@SuppressWarnings("unchecked")
	public static KeyValue<String,Integer>[] getAllSampleRate(String[] rates){
		KeyValue<String,Integer>[] datas=new KeyValue[rates.length];
		for (int i = 0; i < datas.length; i++) {
			datas[i]=new KeyValue<String,Integer>(rates[i] + "Hz",Integer.valueOf(rates[i]));
		}
		return datas; 
	}
}
